package com.tzbank.exception;

import com.tzbank.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author  youkun
 *
 *  公共异常
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler extends Exception{

    /**
     *  @ExceptionHandler(value = Exception.class):声明要捕获的异常类
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Map<String,Object> handle(Exception e, HttpServletRequest request){
        //log 记录错误信息
    	e.printStackTrace();
        return ResultUtil.resultMap("系统异常","-1",e.getMessage());
    }

}
